package Refereces;

import Beans.EJB_Refereces.IRoomStyleRef;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.List;
import java.util.Iterator;

import locale.LocaleConf;
import Entities.RoomStatusEntity;

/**
 * Created by IntelliJ IDEA.
 * User: mchebanenko
 * Date: 4-Jan-2011
 * Time: 3:58:49 PM
 * To change this template use File | Settings | File Templates.
 */
public class FltReference {

    private List roomStyle;
    private List roomCount;
    private List roomPlaces;
    private List roomStatusRef;

    public List getRoomStyle() {
        if( roomStyle==null){
            try{
                Context cont = new InitialContext();
                roomStyle = ((IRoomStyleRef) cont.lookup("HotelManager/RoomStyleRefBean/local")).getRoomStyles();
            } catch (Exception e) {
                e.printStackTrace();
                return  null;
            }
        }
        return roomStyle;
    }

    public void setRoomStyle(List roomStyle) {
        this.roomStyle = roomStyle;
    }

    public List getRoomCount() {
        if( roomCount==null){
            try{
                Context cont = new InitialContext();
                roomCount = ((IRoomStyleRef) cont.lookup("HotelManager/RoomStyleRefBean/local")).getRoomCount();
            } catch (Exception e) {
                e.printStackTrace();
                return  null;
            }
        }
        return roomCount;
    }

    public void setRoomCount(List roomCount) {
        this.roomCount = roomCount;
    }

    public List getRoomPlaces() {
        if( roomPlaces==null){
            try{
                Context cont = new InitialContext();
                roomPlaces = ((IRoomStyleRef) cont.lookup("HotelManager/RoomStyleRefBean/local")).getRoomPlaces();
            } catch (Exception e) {
                e.printStackTrace();
                return  null;
            }
        }
        return roomPlaces;
    }

    public void setRoomPlaces(List roomPlaces) {
        this.roomPlaces = roomPlaces;
    }

    public  List getRoomStatusRef() {
       if( roomStatusRef==null){
            try{
                Context cont = new InitialContext();
                roomStatusRef  =  ((IRoomStyleRef) cont.lookup("HotelManager/RoomStyleRefBean/local")).getRoomStatusRef();
            } catch (Exception e) {
                e.printStackTrace();
                return  null;
            }
        }
        return  roomStatusRef;
    }



    public String getRoomStatusFromRef(String val) {
       String roomStatusFromRef ="";

            try{
                if( roomStatusRef==null){
                    getRoomStatusRef();
                     if( roomStatusRef!=null){
                        Iterator i = roomStatusRef.iterator();
                        while(i.hasNext()){
                           RoomStatusEntity rs = (RoomStatusEntity) i.next();
                           if(rs.getStatus_id()==Integer.parseInt(val)){
                             return roomStatusFromRef = rs.getStatus_id().toString();
                           }
                        }
                     }
                } else{
                     Iterator i = roomStatusRef.iterator();
                        while(i.hasNext()){
                           //RoomStatusEntity rs = (RoomStatusEntity) i.next();
                           Object[] rs =(Object[]) i.next();

                           if(rs[0].toString().equals(val)){
                             return roomStatusFromRef = LocaleConf.getLocalized(rs[2].toString());
                           }

                           /*if(rs.getStatus_id()==Integer.parseInt(val)){
                             return roomStatusFromRef = rs.getStatus_id().toString();
                           }*/
                        }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return  roomStatusFromRef;
            }
        return roomStatusFromRef;
    }
}
